Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

tsgo was silently ignoring JavaScript files when allowJs was not enabled, while tsc reports error TS6504. This made tsgo less helpful for users accidentally compiling .js files.

Changes

Modified internal/compiler/filesparser.go:

  • Added diagnostic check in parseTask.load() to detect JS files without allowJs for all file inclusion paths
  • Check now applies to root files, triple-slash references, type references, and all other file loading paths
  • Uses existing processingDiagnosticKindExplainingFileInclude infrastructure to report the error with file inclusion context

Modified internal/compiler/fileloader.go:

  • Updated addRootTask to include files with extensions even if unsupported, so they can be properly diagnosed in the common load path

The diagnostic check is now placed in the common file loading path (parseTask.load()), similar to how TypeScript's getSourceFileFromReferenceWorker is called by processSourceFile for all file types.

Test baselines updated to match TypeScript compiler output.

Original prompt

This section details on the original issue you should resolve

<issue_title>Missing error when JS file compiled without allowJs on</issue_title>
<issue_description>## Steps to reproduce


D:\Throwaway\corsarepro>tsc a.js
error TS6504: File 'a.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
  The file is in the program because:
    Root file specified for compilation


Found 1 error.


D:\Throwaway\corsarepro>tsgo a.js

D:\Throwaway\corsarepro>
```</issue_description>

<agent_instructions>Use print debugging and `go test -v` to trace why the file is not being included or errored on for the test case diff mentioned in the issue thread. Print debugging with the tsgo binary on the example in the issue itself may also work.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@jakebailey</author><body>
I assume this is https://github.com/microsoft/typescript-go/blob/05f4d69f81d416946ce46a374d91b78c0fbd37c8/testdata/baselines/reference/submodule/compiler/checkJsFiles6.errors.txt.diff#L5</body></comment_new>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing error when JS file compiled without allowJs Add missing TS6504 diagnostic for JavaScript files without allowJs Nov 15, 2025
Copilot AI requested a review from jakebailey November 15, 2025 19:48
Copilot finished work on behalf of jakebailey November 15, 2025 19:48
@jakebailey jakebailey marked this pull request as ready for review November 19, 2025 20:52
Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this seems fine?

Copilot finished reviewing on behalf of jakebailey November 19, 2025 20:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds the missing TS6504 diagnostic for JavaScript files compiled without the allowJs option enabled. Previously, tsgo silently ignored these files while tsc reports a helpful error message, making tsgo less user-friendly.

Key Changes

  • Modified internal/compiler/fileloader.go to detect JavaScript files and report TS6504 diagnostic when allowJs is not enabled
  • Updated 26 test baseline files to reflect the new behavior, showing convergence with TypeScript's behavior

Reviewed Changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/compiler/fileloader.go Added logic to detect JS files without allowJs and report TS6504 diagnostic with file inclusion context
testdata/baselines/reference/submodule/compiler/checkJsFiles6.errors.txt.diff Removed diff showing convergence - now properly reports TS6504 for JS files
testdata/baselines/reference/submodule/compiler/checkJsFiles6.errors.txt Added TS6504 error alongside existing TS5052 error
testdata/baselines/reference/submodule/compiler/jsFileCompilationWithoutJsExtensions.errors.txt.diff Removed diff showing convergence
testdata/baselines/reference/submodule/compiler/jsFileCompilationWithoutJsExtensions.errors.txt Added TS6504 error for JS file compilation
testdata/baselines/reference/submodule/conformance/nodeModulesAtTypesPriority.errors.txt.diff Removed diff showing convergence for node_modules JS files
testdata/baselines/reference/submodule/conformance/nodeModulesAtTypesPriority.errors.txt Added TS6504 errors for JS files in node_modules
testdata/baselines/reference/submodule/conformance/bundlerNodeModules1(module=preserve).errors.txt.diff Removed diff for bundler module resolution
testdata/baselines/reference/submodule/conformance/bundlerNodeModules1(module=preserve).errors.txt Added TS6504 errors for .cjs and .js files
testdata/baselines/reference/submodule/conformance/bundlerNodeModules1(module=esnext).errors.txt.diff Removed diff for esnext module
testdata/baselines/reference/submodule/conformance/bundlerNodeModules1(module=esnext).errors.txt Added TS6504 errors for bundler with esnext
testdata/baselines/reference/submodule/conformance/bundlerConditionsExcludesNode(module=preserve).errors.txt.diff Removed diff for bundler conditions
testdata/baselines/reference/submodule/conformance/bundlerConditionsExcludesNode(module=preserve).errors.txt Added TS6504 errors for .node.js and .web.js files
testdata/baselines/reference/submodule/conformance/bundlerConditionsExcludesNode(module=esnext).errors.txt.diff Removed diff for esnext with bundler conditions
testdata/baselines/reference/submodule/conformance/bundlerConditionsExcludesNode(module=esnext).errors.txt Added TS6504 errors for conditional JS files
testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt.diff Removed diff for node16 module
testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt Added TS6504 error for exports with node16
testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node18).errors.txt.diff Removed diff for node18 module
testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node18).errors.txt Added TS6504 error for exports with node18
testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node20).errors.txt.diff Removed diff for node20 module
testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=node20).errors.txt Added TS6504 error for exports with node20
testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt.diff Removed diff for nodenext module
testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt Added TS6504 error for exports with nodenext
testdata/baselines/reference/submodule/conformance/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt.diff Removed diff for bundler module resolution
testdata/baselines/reference/submodule/conformance/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt Added TS6504 errors for multiple JS files with bundler resolution
testdata/baselines/reference/submodule/conformance/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt.diff Removed diff for node16 module resolution
testdata/baselines/reference/submodule/conformance/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt Added TS6504 errors for multiple JS files with node16 resolution

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
libFile: libFile,
includeReason: includeReason,
})
} else if tspath.HasExtension(absPath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good but arent we currently checking this only for root files and not for resolved triple slash refs or project reference files etc as we did in strada

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true; Strada had this in getSourceFileFromReferenceWorker which was called by processSourceFile, so we do need to do this somewhere else.

Let's try this for fun:

@copilot Reexamine program.ts's getSourceFileFromReferenceWorker, callers, etc, and place this check in the correct place in the Go implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b07f77b. Moved the check from addRootTask to parseTask.load() so it now catches all file inclusion paths (root files, triple-slash references, type references, etc.). Tested with both tsgo a.js and triple-slash references like /// <reference path="helper.js" /> - both now correctly report TS6504.

Moved the TS6504 diagnostic check from addRootTask to parseTask.load() so it catches all file inclusion paths (root files, triple-slash refs, type refs, etc.), not just root files. This matches TypeScript's behavior where getSourceFileFromReferenceWorker is called for all file types.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI requested a review from jakebailey November 20, 2025 22:55
Copilot finished work on behalf of jakebailey November 20, 2025 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing error when JS file compiled without allowJs on

3 participants